﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ProjectSheduleAnalyst
{
    public partial class ViewLessonsForm : Form
    {
        private DB_Access dba = new DB_Access();

        public ViewLessonsForm()
        {
            InitializeComponent();
            this.Text = "Просмотр доступных занятий";
        }

        private void CloseViewLesllonButton_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void ViewLessonsForm_Load(object sender, EventArgs e)
        {
            //ЗАГРУЗКА ЗАНЯТИЙ
            DataSet dsLessons = dba.FillGrid("SelectLessonsInformation", "Lessons");
            dgvViewLessons.DataSource = dsLessons.Tables["Lessons"].DefaultView;

            dgvViewLessons.Columns[0].Visible = false;
            dgvViewLessons.Columns[1].Visible = false;
            dgvViewLessons.Columns[3].Visible = false;
            dgvViewLessons.Columns[7].Visible = false;
            dgvViewLessons.Columns[9].Visible = false;
            dgvViewLessons.Columns[12].Visible = false;

            dgvViewLessons.Columns[2].HeaderText = "Предмет";
            dgvViewLessons.Columns[4].HeaderText = "Фамилия";
            dgvViewLessons.Columns[5].HeaderText = "Имя";
            dgvViewLessons.Columns[6].HeaderText = "Отчество";
            dgvViewLessons.Columns[8].HeaderText = "Курс";
            dgvViewLessons.Columns[10].HeaderText = "Группа";
            dgvViewLessons.Columns[11].HeaderText = "Подгруппа";
            dgvViewLessons.Columns[13].HeaderText = "Тип аудитории";
        }

        private void DeleteLessonButton_Click(object sender, EventArgs e)
        {
            if (
                MessageBox.Show("Удалить выбранное занятие?", "Предупреждение!",
                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                dba.MySQLquery("DELETE FROM LESSONS WHERE ID='"
                    + dgvViewLessons.CurrentRow.Cells[0].Value.ToString() + "'");
            }
            DataSet dsLessons = dba.FillGrid("SelectLessonsInformation", "Lessons");
            dgvViewLessons.DataSource = dsLessons.Tables["Lessons"].DefaultView;
        }

        private void CreateNewLessonButton_Click(object sender, EventArgs e)
        {
            LessonCreationForm LCF = new LessonCreationForm();
            //LCF.Show();

            if (LCF.ShowDialog() == DialogResult.OK)
            {
                DataSet dsLessons = dba.FillGrid("SelectLessonsInformation", "Lessons");
                dgvViewLessons.DataSource = dsLessons.Tables["Lessons"].DefaultView;
            }
        }


    }
}
